package com.siqi.hr.spring.converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.core.convert.converter.Converter;

/**
 * spring自定义字符串转日期格式转换器(xiaogq)
 */
public class StringToDateConverter implements Converter<String, Date> {
	public Date convert(String source){
	    if (StringUtils.isEmpty(source)) {
	        return null;
	    }
	    DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd");
	    Date date = null;
	    try {
	      date = dateTimeFormat.parse(source);
	    } catch (ParseException e) {
	      e.printStackTrace();
	    }
	    return date;
	  }
}
